import axios, { type AxiosInstance } from 'axios'




class Reqeust {
  BaseUrl: string
  token: string | null
  request: AxiosInstance

  constructor() {
    this.BaseUrl = 'http://10.40.92.176:8071'
    this.token = null
    this.request = axios.create({
      baseURL: this.BaseUrl,
      headers: {
        token: this.token
      }
    })
    this.requestInterceptor()
  }




  requestInterceptor() {

    this.request.interceptors.request.use((config) => {
      // 在发送请求之前做些什么
      console.log(this.token, '000');

      return config;
    }, function (error) {
      // 对请求错误做些什么
      return Promise.reject(error);
    });

    // 添加响应拦截器
    this.request.interceptors.response.use((response) => {
      // 对响应数据做点什么
      console.log(this.token, '123');
      if (!this.token) {
        this.token = '1234567'
      }
      console.log(this.token, '456');
      return response;
    }, function (error) {
      // 对响应错误做点什么
      return Promise.reject(error);
    });

  }


  getque() {
    return this.request
  }
}



class NewRequest extends Reqeust {

  constructor() {
    super()
  }


  getAxios() {
    return this.getque()
  }
}




export default new NewRequest()